<template>
  <a-modal
    :title="title"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="
      () => {
        this.visible = false
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="客户名称" prop="cVouchType">
          <a-input v-model="entity.cVouchType" autocomplete="off" placeholder="客户名称" />
        </a-form-model-item>
        <a-form-model-item label="工单类型" prop="cVouchName">
          <a-select v-model="entity.TransactionType" style="width: 100%" placeholder="工单类型">
            <a-select-option v-for="item in list" :key="item.Id" :value="item.DicName">
              {{ item.DicName }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="服务费用" prop="cVouchName">
          <a-input v-model="entity.cVouch" autocomplete="off" placeholder="服务费用" />
        </a-form-model-item>
        <a-form-model-item label="业务员" prop="salesman">
          <a-select v-model="entity.salesman" style="width: 100%"> </a-select>
        </a-form-model-item>
        <!-- <a-form-model-item label="回馈信息" prop="feedback">
          <a-input v-model="entity.feedback" autocomplete="off" placeholder="回馈信息" />
        </a-form-model-item> -->
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      list: [],
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  created() {
    this.getSelsct()
  },
  methods: {
    getSelsct() {
      this.$http
        .post('/Base_BasicData/Base_DictionaryMain/GetTheDataByDicKey', {
          Condition: 'DicKey',
          Keyword: 'WorkOrderType'
        })
        .then(res => {
          if (res.Success) {
            this.list = res.Data.DictionaryDetailsList
          }
        })
    },
    init() {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()
      this.title = title
      if (id) {
        this.loading = true
        this.$http.post('/Base_BasicData/VouchType/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
      })
    }
  }
}
</script>
